
/**普通计算器相关Start
 * ***************************************************************************
 */

$("#tslvjsq input").change(function() {
	var oldNum = $("#tslvjsq .old-num").val();
	var addNum = $("#tslvjsq .add-num").val();
	if(addNum == "" | addNum == undefined | oldNum == "" | oldNum == undefined) {
		return;
	}
	oldNum = parseInt(oldNum);
	addNum = parseInt(addNum);
	var r = (addNum / oldNum - 1) * 100;
	
	$("#tslvjsq .up-num").text(r.toFixed(2));

});

var formula = $("#show #formula");
var result = $("#show #result");

var equal = false;

$("#jsqTable td").click(function() {
	var td = $(this);
	var td_text = td.text();
	var resultText = result.text() + td_text;
	var re1 = /[\d\.]+/im;
	if(re1.test(td_text)) {
		if(equal) {
			formula.text("");
			resultText = td_text;
			equal = false;
		}
		if(td_text == "." && result.text().indexOf(".") != -1) {
			return;
		}
		result.text(resultText);
		return;
	}
	var hou = result.text().charAt(result.text().length - 1);
	var re2 = /[\+\-\÷\×]+/im;
	if(re2.test(td_text)) {
		if(equal) {
			formula.text("");
			equal = false;
		}
		if(!result.text()) {
			return;
		}
		if(hou == ".") {
			resultText = result.text();
			resultText = resultText.substring(0, resultText.length - 1) + td_text;
		}
		var temp = formula.text() + resultText;
		formula.text(temp);
		result.text("");
		return;
	}

	if(td_text == "=") {
		var hou2 = formula.text().charAt(formula.text().length - 1);
		var re2 = /[\+\-\÷\×]+/im;
		var formulaText = formula.text();
		resultText = result.text();
		if(re2.test(hou2) && !resultText) {
			formulaText = formulaText.substring(0, formulaText.length - 1);
		}
		if(hou == ".") {
			resultText = resultText.substring(0, resultText.length - 1);
		}
		formulaText += resultText;
		if(!formulaText) {
			return;
		}

		formula.text(formulaText + "=");
		formulaText = formulaText.replace(/\×/g, "*");
		formulaText = formulaText.replace(/\÷/g, "/");
		var aaa = eval(formulaText);
		result.text(eval(formulaText));
		equal = true;
	}
});

$("#jsqTable #j-ce").click(function() {
	result.text("");
})

$("#jsqTable #j-c").click(function() {
	formula.text("");
	result.text("");
})

$("#jsqTable #j-back").click(function() {
	if(result.text()) {
		result.text(result.text().substring(0, result.text().length - 1));
	}
})

/**普通计算器相关End
 * ***************************************************************************
 */